package com.example.project1;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.Fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;



import java.util.List;



public class weixin_pengyouquan extends Fragment {

    private View view;//定义view用来设置fragment的layout
    public RecyclerView mCollectRecyclerView;//定义RecyclerView
    //定义以goodsentity实体类为对象的数据集合
    private ArrayList<GoodsEntity> goodsEntityList = new ArrayList<GoodsEntity>();
    //自定义recyclerveiw的适配器
    private CollectRecycleAdapter mCollectRecyclerAdapter;


    public weixin_pengyouquan() {
        // Required empty public constructor
    }


    @Override
    @Nullable

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        //获取fragment的layout
        view = inflater.inflate(R.layout.fragment_pengyouquan, container, false);
        //对recycleview进行配置
        initRecyclerView();
        //模拟数据
        initData();
        return view;

    }
    /**
     * TODO 模拟数据
     */
    private void initData() {

            GoodsEntity goodsEntity1=new GoodsEntity();
            goodsEntity1.setGoodsName("崔健");
            goodsEntityList.add(goodsEntity1);
            GoodsEntity goodsEntity2=new GoodsEntity();
            goodsEntity2.setGoodsName("毛阿敏");
            goodsEntityList.add(goodsEntity2);
            GoodsEntity goodsEntity3=new GoodsEntity();
            goodsEntity3.setGoodsName("刘欢");
            goodsEntityList.add(goodsEntity3);
            GoodsEntity goodsEntity4=new GoodsEntity();
            goodsEntity4.setGoodsName("那英");
            goodsEntityList.add(goodsEntity4);
            GoodsEntity goodsEntity5=new GoodsEntity();
            goodsEntity5.setGoodsName("腾格尔");
            goodsEntityList.add(goodsEntity5);
            GoodsEntity goodsEntity6=new GoodsEntity();
            goodsEntity6.setGoodsName("孙楠");
            goodsEntityList.add(goodsEntity6);
            GoodsEntity goodsEntity7=new GoodsEntity();
            goodsEntity7.setGoodsName("韩磊");
            goodsEntityList.add(goodsEntity7);
            GoodsEntity goodsEntity8=new GoodsEntity();
            goodsEntity8.setGoodsName("韩红");
            goodsEntityList.add(goodsEntity8);
            GoodsEntity goodsEntity9=new GoodsEntity();
            goodsEntity9.setGoodsName("李健");
            goodsEntityList.add(goodsEntity9);
            GoodsEntity goodsEntity10=new GoodsEntity();
            goodsEntity10.setGoodsName("张靓颖");
            goodsEntityList.add(goodsEntity10);

    }

    /**
     * TODO 对recycleview进行配置
     */
    private void initRecyclerView() {
        //获取RecyclerView
        mCollectRecyclerView=(RecyclerView)view.findViewById(R.id.collect_recyclerView);
        //创建adapter
        mCollectRecyclerAdapter = new CollectRecycleAdapter(getActivity(), goodsEntityList);
        //给RecyclerView设置adapter
        mCollectRecyclerView.setAdapter(mCollectRecyclerAdapter);
        //设置layoutManager,可以设置显示效果，是线性布局、grid布局，还是瀑布流布局
        //参数是：上下文、列表方向（横向还是纵向）、是否倒叙
        mCollectRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        //mCollectRecyclerView.setLayoutManager(new GridLayoutManager(this.getActivity(), 3));//不能只用this
        //设置item的分割线
        mCollectRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(),DividerItemDecoration.VERTICAL));
        //RecyclerView中没有item的监听事件，需要自己在适配器中写一个监听事件的接口。参数根据自定义
        mCollectRecyclerAdapter.setOnItemClickListener(new CollectRecycleAdapter.OnItemClickListener() {
            @Override
            public void OnItemClick(View view, GoodsEntity data) {
                //此处进行监听事件的业务处理
                Toast.makeText(getActivity(),"您点击的歌手是:"+data.getGoodsName(), Toast.LENGTH_SHORT).show();
            }
            @Override
            public  void OnItemLongClick(View view, GoodsEntity data) {
                //Toast.makeText(getActivity(), "long click:"+data.getGoodsPrice(), Toast.LENGTH_SHORT).show();
            }
        });
    }
}
